package com.cyf.app;

import com.cyf.app.network.bean.parkinglock.*;
import com.cyf.app.service.AppParkingLockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * 车位相关
 * Created by cage on 2017/4/26.
 */
@RestController
@Api("app车位相关api")
@RequestMapping(value = "app/parkingLock")
public class AppParkingLockHttpController {

    @Autowired
    private AppParkingLockService appParkingLockService;

    @ApiOperation(value = "添加地锁")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "name", value = "名称", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "macAddress", value = "MAC地址", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "lockStatus", value = "锁的状态 1下降 0升起", dataType = "int", required = true, paramType = "query")
    })
    @PostMapping(value = "/addLock")
    public AppAddLockRsp addParkingLock(@RequestParam String token,
                                        @RequestParam String name,
                                        @RequestParam String macAddress,
                                        @RequestParam int lockStatus) {
        AppAddLockReq req = new AppAddLockReq();
        req.setToken(token);
        req.setName(name);
        req.setMacAddress(macAddress);
        req.setLockStatus(lockStatus);
        return appParkingLockService.addLock(req);
    }

    @ApiOperation(value = "查询地锁列表")
    @ApiImplicitParam(name = "token", value = "token", dataType = "string", required = true, paramType = "query")
    @PostMapping(value = "/getLocks")
    public AppGetLocksRsp getParkingLocks(@RequestParam String token) {
        AppGetLocksReq req = new AppGetLocksReq();
        req.setToken(token);
        return appParkingLockService.getParkingLocks(req);
    }

    @ApiOperation(value = "编辑地锁")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "parkingLockId", value = "地锁id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "name", value = "名称", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "macAddress", value = "MAC地址", dataType = "int", required = true, paramType = "query")
    })
    @PostMapping(value = "/editLock")
    public AppEditLockRsp editParkingLock(@RequestParam String token,
                                          @RequestParam int parkingLockId,
                                          @RequestParam String name,
                                          @RequestParam String macAddress) {
        AppEditLockReq req = new AppEditLockReq();
        req.setToken(token);
        req.setParkingLockId(parkingLockId);
        req.setName(name);
        req.setMacAddress(macAddress);
        return appParkingLockService.editParkingLock(req);
    }

    @ApiOperation(value = "删除地锁")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "parkingLockId", value = "地锁id", dataType = "int", required = true, paramType = "query")
    })
    @PostMapping(value = "/deleteLock")
    public AppDeleteLockRsp deleteParkingLock(@RequestParam String token,
                                              @RequestParam int parkingLockId) {
        AppDeleteLockReq req = new AppDeleteLockReq();
        req.setToken(token);
        req.setParkingLockId(parkingLockId);
        return appParkingLockService.deleteParkingLock(req);
    }

    @ApiOperation(value = "共享地锁")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "parkingLockId", value = "地锁id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "shareStatus", value = "共享地锁 1共享 0不共享", dataType = "int", required = true, paramType = "query")
    })
    @PostMapping(value = "/shareLock")
    public AppShareLockRsp shareParkingLock(@RequestParam String token,
                                            @RequestParam int parkingLockId,
                                            @RequestParam int shareStatus) {
        AppShareLockReq req = new AppShareLockReq();
        req.setToken(token);
        req.setParkingLockId(parkingLockId);
        req.setShareStatus(shareStatus);
        return appParkingLockService.shareParkingLock(req);
    }

    @ApiOperation(value = "升降锁通知")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "parkingLockId", value = "地锁id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "lockStatus", value = "锁的状态 1下降 0升起", dataType = "int", required = true, paramType = "query")
    })
    @PostMapping(value = "/lockNotice")
    public AppLockNoticeRsp lockNotice(@RequestParam String token,
                                                 @RequestParam int parkingLockId,
                                                 @RequestParam int lockStatus) {
        AppLockNoticeReq req = new AppLockNoticeReq();
        req.setToken(token);
        req.setParkingLockId(parkingLockId);
        req.setLockStatus(lockStatus);
        return appParkingLockService.lockNotice(req);
    }
}
